<?
include_once '../library.php';
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<title>SK Communications A11Y Score Board</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!-- Bootstarap Version -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="../bootstrap/js/bootstrap.js"></script>
<link type="text/css" rel="stylesheet" href="../bootstrap/css/bootstrap.css" />
<!-- //Bootstarap Version -->
<script type="text/javascript" src="../js/common.js"></script>
<!-- Basic Style -->
<link type="text/css" rel="stylesheet" href="../css/style.css" />
<!-- //Basic Style -->
</head>
<body>
<?
$table_name = "service_url";
$select_array = array("*");
$url_nate = array();
$url_cyworld = array();
$service_url = selectDB($table_name, $select_array, "1=1 ORDER BY flag DESC, rank ASC");

$category = $_POST['category'];
$data = $_POST['data'];
$count = count($data) / 5;

for($i=0; $i<$count; $i++){
	$data1 = array();
	for($j=0; $j<5; $j++){
		$value = array_shift($data);
		array_push($data1, $value);
	}
	
	$data_s[$i] = $data1;
}

$column_arr = array("title", "url", "rank", "flag");

for($i=0; $i<count($data_s); $i++){
	$title = $data_s[$i][1];
	$url = $data_s[$i][2];
	$rank = $data_s[$i][3];
	$flag = $data_s[$i][4];
	$value_arr = array($title, $url, $rank, $flag);
	
	
	if($data_s[$i][0] == "new"){
		//Insert DB
		$value_arr = array($category, $title, $url, $rank, $flag); 
		$column_arr = array("category", "title", "url", "rank", "flag");
		$result = insertDB($table_name, $value_arr, $column_arr);
	}else{
		//Update DB
		$condition = "idx = ".$data_s[$i][0];
		$result = updateDB($table_name, $value_arr, $column_arr, $condition);
	}
	
	if($result !=0){
		$db_update_flag = "0";
		alert("업데이트 에러", "데이터베이스에 업데이트 하던 중 오류가 발생하였습니다.", "http://uiguide.skcomms.co.kr/tools/a11y/admin/admin.php");
		exit;
	}else{
		$db_update_flag = "1";
	}
}

if($db_update_flag = "1"){
	alert("DB업데이트 성공", "성공적으로 DB에 업데이트 되었습니다.", "/tools/a11y/admin/admin.php");
}else{
	alert("DB업데이트 실패", "알 수 없는 이유로 DB업데이트가 실패되었습니다.", "/tools/a11y/admin/admin.php");
}
?>
</body>
</html>
